﻿using Dealin.Code;
using Dealin.Domain.Entity.DeviceManage;
using Dealin.Domain.IRepository.DeviceManage;
using Dealin.Repository.DeviceManage;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dealin.Application.DeviceManage
{
    public  class LEDApp
    {
        private ILEDRepository service = new LEDRepository();


        public List<LEDEntity> GetList(string keyword = "")
        {
            var expression = ExtLinq.True<LEDEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                var intKeyword = 0;
                try
                {
                    intKeyword = Convert.ToInt32(keyword);
                    expression = expression.And(t => t.F_Port == (intKeyword));
                   
                }
                catch
                {
                }
            }
            return service.IQueryable(expression).OrderBy(t => t.F_Port ).ToList();
        }
        public LEDEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        public void DeleteForm(string keyValue)
        {

            service.Delete(t => t.F_Id == keyValue);
        }
        public void SubmitForm(LEDEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.Modify(keyValue);
                service.Update(entity);
            }
            else
            {
                entity.Create();
                service.Insert(entity);
            }
        }
    }
}
